package waggle.server;

//import org.apache.log4j.Logger;
import waggle.client.bean.User;

/**
 * The default service implementation of {@link SessionIdService}.
 * 
 */
// @Singleton
public class SessionIdServiceImpl implements SessionIdService {

  /**
   * The {@link Logger} used for logging events.
   */
//  Logger log = Logger.getLogger(SessionIdServiceImpl.class);

  /**
   * Checks the user table for a matching session id. If a user is found,
   * returns the user id.
   * 
   * @see org.rebioma.server.services.SessionIdService#getUserBySessionId(java.lang.String)
   */
  public User getUserBySessionId(String sid) {
	  //kayjean
	  return null;
	  
//    Session session = HibernateUtil.getCurrentSession();
//    boolean isFirstTransaction = HibernateUtil.beginTransaction(session);
//    try {
//      System.out.println("session before calling getUserBySessionId is "
//          + session.isOpen());
//      User user = (User) session.createCriteria(User.class).add(
//          Restrictions.eq("sessionId", sid)).uniqueResult();
//      if (isFirstTransaction) {
//        HibernateUtil.commitCurrentTransaction();
//      }
//      // user.setRoles(new HashSet<Role>(roleD));
//      return user;
//    } catch (HibernateException e) {
//      HibernateUtil.rollbackTransaction();
//      log.error("Error: " + e.getMessage(), e);
//      return null;
//    } finally {
//      // session.close();
//    }
  }

  /**
   * Checks the user table for a matching session id and returns true if there
   * is a match.
   * 
   * @see org.rebioma.server.services.SessionIdService#isSessionIdValid(java.lang
   *      .String)
   */
  public boolean isSessionIdValid(String sid) {
    User user = getUserBySessionId(sid);
    return user != null;
  }

}
